package com.example.androidsensors;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.hardware.Sensor;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.ContextThemeWrapper;
import android.widget.ArrayAdapter;

public class SensorsInfoDialogFragment extends DialogFragment{
	private ArrayAdapter<String> adapter;
	private Context context;
	private List<Sensor> deviceSensors;
	
	public void setDialog(Context context, List<Sensor> deviceSensors){
		this.deviceSensors = deviceSensors;
		this.context = context;
	}
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState){
		AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.MyTheme));
		ArrayList<String> rowTexts = new ArrayList<String>();
		
        for(int i=0; i<deviceSensors.size();i++){
        	Sensor s = deviceSensors.get(i);
        	rowTexts.add(s.getName().toUpperCase() + 
        			"\nType: " + s.getType() + 
        			"\nVendor: " + s.getVendor() + 
        			"\nVersion: " + s.getVersion() + 
        			"\nResolution: " + s.getResolution() + 
        			"\nMax Power Use(mA): " + s.getPower() + 
        			"\nMax Range: " + s.getMaximumRange() + 
        			"\nMin Delay(micro sec): " + s.getMinDelay());
        }
        adapter = new ArrayAdapter<String>(context, R.layout.info_list_row, rowTexts);
        builder.setTitle("Wbudowane sensory");
        builder.setAdapter(adapter, null);
		return builder.create();
	}
}
